package com.xdemo.community.handler;

import com.xdemo.community.manager.IPersonalServerManager;
import com.xdemo.community.server.pool.EManager;
import com.xdemo.community.server.pool.ManagerPool;
import com.xdemo.core.MessageType;
import com.xdemo.core.msg.BreakServerMessage;
import com.xdemo.core.msg.RegisterServerMessage;
import com.xdemo.handler.IMessageAction;
import com.xdemo.msg.IMessage;

public class ServerMessageAction implements IMessageAction<Integer> {
	
	private final Integer[] types = {MessageType.RegisterServer};

	@Override
	public void doAction(IMessage<Integer> message) {
		IPersonalServerManager _serverManager = (IPersonalServerManager)ManagerPool.getManager(EManager.PersonalServer);
		switch(message.getType()) {
		case MessageType.RegisterServer:{
			RegisterServerMessage _msg = (RegisterServerMessage)message;
			_serverManager.registerServer(_msg.getServerId(), _msg.getServer());
			break;
		}
		case MessageType.BreakServer:{
			BreakServerMessage _msg = (BreakServerMessage)message;
			_serverManager.breakServer(_msg.getServerId());
			break;
		}
		}
	}

	@Override
	public Integer[] getTypes() {
		return types;
	}

}
